/**
 * 该模块用于维护主页
 */

import { getBaseCategoryList, getSwiperApi, getFloorApi } from '@/api/home'

const state = {
  categoryList: [],
  // 轮播图
  swiperList: [],
  floorList: []
}
const mutations = {
  // 修改state的数据
  CATEGORYList (state, params) {
    state.categoryList = params.slice(0, 16)
  },
  // 修改轮播图数据
  CATESWIPERList (state, params) {
    state.swiperList = params
  },
  // 修改楼层数据
  CTAEFLOORList (state, params) {
    state.floorList = params
  }
}

const actions = {
  // 请求三级联动的数据
  async categoryList ({ commit }) {
    const res = await getBaseCategoryList()
    if (res.code === 200) commit('CATEGORYList', res.data)
  },
  // 请求轮播图数据
  async cateSwiperList ({ commit }) {
    const res = await getSwiperApi()
    if (res.code === 200) commit('CATESWIPERList', res.data)
  },
  // 楼层数据
  async cateFloorList ({ commit }) {
    const res = await getFloorApi()
    if (res.code === 200) commit('CTAEFLOORList', res.data)
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
